#!/bin/bash
var1=$1
tmp_file=~/.__tmp_go
ouput_list=`find . -name "*$var1*" ! -name "*.i" ! -name "*.pyc" ! -name "*.orig"`
find . -name "*$var1*" ! -name "*.i" ! -name "*.pyc" ! -name "*.orig" > $tmp_file
lines=`awk '{print NR}' $tmp_file|tail -n1`
start_line='----------------start------------------'
end_line='-----------------end-------------------'
echo $start_line
counter=1
for i in $ouput_list
do
    echo "$counter ) $i"
    counter=$(($counter+1))
done
if [ -z $lines ]; then
    lines=0
    echo 共$lines条记录
    echo $end_line
    exit 0
fi
echo 共$lines条记录
echo
echo -n "which file do you want to open? "
read num1
#if [ "$num1" = "n" ]; then
#    echo "Good Bye."
#    exit 1 
#fi
case "$num1" in
    [nN]* )
    echo "Good Bye."
    exit 0
esac
choose=`awk 'NR=='$num1' {print;exit}' $tmp_file`
# -----------------------------------------
if [ -d $choose ]; then
    echo "open <Director $choose>"
    nautilus $choose
#    cd $choose
else
    ext=`echo $choose | awk -F . '{print $NF}'`
    case "$ext" in
    jpeg|jpg|png|gif|bmp)
        echo "open <Picture $choose>"
        eog $choose;;
    swf|rm|rmvb|avi|mp4|flv|mkv)
        echo "open video:$choose"
        totem $choose;;
    * )
        echo "open text: $choose"
        vi $choose;;
    esac
fi
# -----------------------------------------
#echo "open $choose"
#vi $choose
echo "finish."
echo $end_line
exit 0
